Hunter’s haphazard hoard of hopefully helpful hacks
Algorithms | Athena workstations at MIT | C | Catholicism | Cloud | Containers | Databases | Distributed systems | Finances | Future topics | GDB | Games | Golang | Grammar and style | Housing | IntelliJ | Interviews | Julia | LaTeX | Linear algebra | Linux | Literature | Mac | Machine learning | Miscellanea | Networks | ONC RPC | Operating systems | Pandoc | Probability | Projects | Python | Raspberry Pi | Screen | Security | Serialization | Shell | Software engineering | SSH | Strength training | Tmux | Version control | Vim | Virtual machines | Visual Studio Code | Visualize C call graphs on a Mac | Web programming | Wolfram Alpha
aws ec2 describe-availability-zones --region us-west-1
check currently-available AZs for regionkubectx +
kubens easily switch contexts and namespaceskubectl get secret orc8r-certs -o go-template='{{range $k,$v := .data}}{{printf "%s:\n" $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}'
print a map of opaque secrets{__name__=~".+"} query
all non-stale metrics
TF_LOG environment variable to one of
TRACE, DEBUG, INFO,
WARN, ERRORterraform-docs
generate module documentationchomp(file("~/.magma/github_access_token")) remove
newline from file inputswagger.yml from godoc commentsswagger mixin merge Swagger specs using go-openapi/analysisInterviews generally fall into 1 of 3 categories - Coding: design and code up a solution to a single problem (coding pad) - DS&A: most coding interviews will require data structures and algorithms (DS&A) insights to complete - Practical: a minority of coding interviews will just focus on practical, day-to-day coding skills - Frontend: if you’re going for a frontend role, you will likely be challenged to build a UI component of some sort - Design: explore and design a high-level architecture for an under-specified problem (virtual whiteboard) - System: most design interviews will require designing a scalable, efficient, robust distributed system - Object-oriented: some design interviews will focus on the design of a single, in-process component - Product: for more frontend or product management type roles, the focus will be on designing an API, and what UX to provide - Behavioral: describe approaches and past experiences (verbal discussion)
Additional notes - Timing: most companies will do 1 hour per interview, where 50-55 minutes are devoted to the actual interview; some however will only allot 45 minutes per interview, where 35-40 minutes are devoted to the interview (e.g. Meta) - Number of questions/parts: most companies only expect 1 question/part per interview; some however expect 2 (potentially completely separate) questions within a single interview (e.g. Meta coding interviews) - Split: behavioral questions will mostly be standalone in their own interview; increasingly I’ve started to see the behavioral component split out into the first 10-15 minutes of each of the other interviews - Idiosyncratic interview types - Bug squash: set up an IDE in a repo and resolve as many bugs as you can (e.g. Stripe) - Technical deep dive: this can either be a discussion-only system design interview (e.g. LinkedIn), or a project retrospective where you present the technical details of a past project (e.g. OpenAI) - Project design: read a project’s technical requirements, then write up a design doc-style one pager on your design recommendations (e.g. Waymo) - Technical trivia: answer technical trivia questions on a topic (e.g. Jump Trading)
Remote-friendly big-tech companies (as of January 2024) - Meta (IC6 and above) - Netflix - Pinterest - Stripe
alias e0="et -c 'tmux -CC new-session -AD -s main' -x devvm7602.ftw0.facebook.com:8080"noti
command
Quantity or
DeliveryDays as an object with validationdatabase/sqlA @ B matrix multiplication of A by
Bssh
command
-vvv max verbosityssh vagrant@localhost -p 2222 specify non-standard
portvagrant ssh-config ssh configuration for each VM,
e.g. which private key to usevagrant ssh cwag_test -- -vvv send SSH options through
vagrant command~/.ssh/known_hosts
public key info for hosts known to the client (file
format) (key
format)
markers (optional), hostnames, keytype, base64-encoded key, comment,
space-delimitedbits, exponent, modulus~/.ssh/config/etc/ssh/ssh_configUserKnownHostsFile=/dev/null don’t pollute user’s
known_hosts fileStrictHostKeyChecking=no don’t enforce
known_hosts entriesIdentityFile indicate which private key to use for
host~/.ssh/authorize_keys
on target server
Settings > Editor > General > Editor Tabs > Tab limitContextual menu > implement interfaceshift shift omni-action<alt-enter> contextual menu<ctrl-tab> switcherctrl ctrl run anything<cmd-up> navigation bar<cmd-alt-y> sync fileInvalidate Caches / Restart nuke caches<cmd-b>, <ctrl-j>
declaration<cmd-shift-b> type declaration<cmd-k> implementations<cmd-shift-k> implements<cmd-j> show usages<cmd-shift-j> find usagesf2, <ctrl-;> next error<shift-f2>, <ctrl-'> previous
error<ctrl-shift-;> next change<ctrl-shift-'> previous change<ctrl-.> next method<ctrl-,> previous method<shift-esc> hide active tool window<cmd-shift-'> maximize tool window<cmd-shift-e> recent locations window<cmd-3> find window<cmd-e> open recent files<cmd-t> terminal window<cmd-o> reveal in file tree<cmd-+> expand all in project menu<cmd-shift--> close all folds<cmd-shift-=> expand all folds<cmd-y> quick definition<cmd-shift-a> version control annotations<cmd-shift-d> file/package structure!*.go exclude-based file maskright click > mark directory as > excluded exclude
specific directories<shift-f6> refactor<shift-f6> <shift-f6> refactor dialogue
(e.g. disable string and comment refactor)<shift-n> create new file<c-n> next autocomplete option<c-p> previous autocomplete option<cmd-l> roll back changed hunk<cmd-r> run<cmd-shift-r> rerun<cmd-shift-t> open tests<alt-tab> cycle split<alt-shift-tab> cycle previous split<ctrl-cmd-n> split vertically<ctrl-cmd-m> split horizontally<ctrl-cmd-z> unsplit<ctrl-cmd-y> unsplit all<ctrl-cmd-o> move tab to opposite split0 varint – int32, int64, uint32, uint64, sint32,
sint64, bool, enum1 64-bit – fixed64, sfixed64, double2 length-delimited – string, bytes, embedded messages,
packed repeated fields5 32-bit – fixed32, sfixed32, float1, else 0protobuf/ptypes/wrappers provides wrapper structs for
Go built-in types, e.g. StringValue,
BytesValue, etc.proto.Equal(protoA, protoB) compare
equality of protobufsproto.Clone(data).(*protos.SubscriberData) clone a
protobufprotoc --go_out=plugins=grpc:. *.proto generate
gRPC-supported protobuf codego mod init github.com/hcgatewood/any-json init Go
modules to import third-party and cross-package code in toy
projectnil, errors.New("zebra") for a response
results in the specified error returned to clientnil, nil for a response results in an error
(error while marshaling) returned to client, even if the
return message is defined as emptyjsonpb produces more-or-less canonical
JSONjson can be
coerced into producing more-or-less canonical JSON
using LinearAlgebra; Diagonal(v) diagonal matrix from
vector vInstall
Python: brew install python3
Install Jupyter:
pip3 install jupyter
Install Julia:
brew cask install julia
Install IJulia, the Julia kernel for Jupyter notebooks (other kernels)
$ julia
julia> using Pkg
julia> Pkg.add("IJulia")Start
Jupyter server: jupyter notebook (from relevant
directory)
Print as
PDF: jupyter nbconvert --to pdf in.ipynb
sh via JSLinux)~/.profile for any login shell, e.g. setting
environment variables~/.bashrc for interactive Bash usage, e.g. aliases~/.bash_profile for Bash-specific login shellshash:
common commands can be added
to hash lookup, superseding normal path lookups
type rm outputs
e.g. rm is hashed (/bin/rm)hash -d vim reload hash table entries for
vimhash -r reload all hash table entriesctrl-r, ctrl-s reverse/forward substring
searchv edit current command in editor, then execute (:cq
from Vim to abort)set editing-mode vi set vi mode
for all Readline-dependent tools!* all previous aruments!^ first of previous aruments!$ last of previous aruments!2 second of previous aruments!2-3 second and third of previous arumentshistory -r read history file and append contents to
history listhistory -a append new history lines to history
filehistory -s add args to end of history list as single
entry!:1 first argument of previous command!:1-2 first and second arguments of previous
command!$ last argument of previous command^cat^bat run previous command with cat
replaced to batopenssl x509 -help 2>&1 | less redirect
stderr to stdoutcat <(echo 1) redirect stdout to anonymous fifo,
then pass fifo to cat as an argumentcomplete -p git get
complete’s completion handling for
git0 indicates successful command1-255 indicates failed command, generally acts as an
error codeecho $? print exit status of most recent commandctrl-c send SIGINTctrl-\ send SIGQUITctrl-z send SIGSTP to suspend programkill kill the process ID from another terminalkill -9 force-kill the process ID from another
terminal, without a clean abortset -x and
set +xexport -fpushd ., popd, dirs to cd via
a stack of directoriesset -euf -o pipefail scripting settings for
safer script exitssh cat <<EOF foo bar EOFVARIABLE=${1:-DEFAULTVALUE} provide
default variable valuefor i in {0..3} ; do echo $i ; done loops
0 1 2 3
for i in $(seq 3) ; do echo $i ; done loops
1 2 3
for (( i = 0 ; i < 3 ; i++ )) ; do echo $i ; done
loops 0 1 2
Reading lines from file ```sh while read p; do echo “$p” done <peptides.txt
# or
cat peptides.txt | while read line; do echo “$line” done ```
if [[ -d tmp ]] && [[ 1 == 1 ]] ; then echo 42 ; else echo 43; fi(($foo < $bar)) arithmetic[[ $foo -lt $bar ]] conditional[[ ! 42 == 42 ]] negate
conditional[[ $foo == "foo" ]] string equality[[ -d $foo ]] exists and is a directory[[ -f $foo ]] exists and is a regular
file[[ -r $foo ]] exists and is readable# spin for the passed number of seconds, defaulting to 10 seconds.
function spin() {
nsec=$(( ${1-10}*10 ))
spin='-\|/'
for (( i = 0 ; i < nsec ; i++ )) ; do
j=$(( i % 4 ))
printf "\r${spin:$j:1}"
sleep .1
done
printf "\r \n"
}set -o vi set vi mode
just for shellshopt -s histappend allow
parallel shells to correctly append to the history filestty -ixon fix
forward search in some terminalsbandwhich
network utilization by various categoriesbroot
simple directory viewereasytag view
and edit audio file tagsentr run
command on changesexport-chrome-bookmarks
export Google Chrome bookmarks and historyffmpeg
audio/video processing (common
commands)
ffmpeg -i input.wav output.mp3 convert WAV file to MP3fkill
improved process killing
:8080 kill process bound to port 8080fortune
random messages from a database (about)
$(brew --prefix)/Cellar/fortune/9708/share/games/fortunes
location of fortune files (for Homebrew fortune
installations)% meta character separating each fortune<tab><tab>-- Thérèse de Lisieux attribution
format (and no " for quotes)strfile catholic generate catholic.dat for
consumption by fortunefzf fuzzy
finder (examples)imagemagick
convert, edit, compose images
convert test.svg test.png convet SVG image to PNGconvert IMG_4281.PNG IMG_4282.PNG -quality 100 golds.pdf
convert multiple images into a single PDFconvert drivers-license-2023.pdf -quality 100 drivers-license-2023.png
convert a multi-page PDF into multiple imagesmagick mogrify -monitor -format png *.HEIC convert all
HEIC images to png formatjless JSON
explorerranger
Vim-like file manager (intro)
~/.config/rc.conf startup commands and key
bindingscw change current filenameS open shell in current directory:bulkrename bulk-rename
selection (select via shift-v):delete delete selection:touch create file (:shell touch create
multiple files at once)rclone sync files and
directories to and from local or cloud storage solutions
rclone serve http . serve local directory and files
over HTTPredshift adjust
display color temperature according to surroundingsrga
seach PDFs, Office documents, and morescc count
lines of code (similar to cloc, loc)watchman
execute commands in response to file modificationsyoutube-dl
download from YouTube, Soundcloud, Funimation, and
othersjohn+spam@gmail.com
delivered to john@gmail.com, but can be filtered e.g. as if
it was spamhttp://www.example.com
(or e.g. http://captive.apple.com
for Macs), in Incognito mode if necessary
- in LaTeX)-- in LaTeX)--- in LaTeX)texcount -merge main.textInstallation
Document generation
Minimal .tex file
\documentclass[12pt]{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\begin{document}
Hello world.
\end{document}e.g.\ normal spacing don’t put wider space after a
particular period$x \text{ is equal to } 42$ normal text in math mode
using the amsmath package\textcolor{gray}{\xmark} change
text color with the xcolor package.bib).bib file and LaTeX
Reference management software like Mendeley creates a BibTeX file
(.bib)
Reference the relevant BibTeX file; e.g. by creating a symlink in the local directory
Cite using the biblatex package
% Minimal example using biblatex
\usepackage[sorting=none]{biblatex}
\addbibresource{bibtex-file.bib}
% ...
\cite{AuthorYear}
\cite[pre-text][post-text]{Author1Year1,Author2Year2}
% ...
\printbibliography{}
% ...\begin{figure}[ht]
\centering
\begin{tikzpicture}[
grow = left,
sibling distance = 2em,
level distance = 8em,
]
\node {payload}
child {node {TLS}
child {node {HTTP} edge from parent[<-,black]}
child {node {IMAP/POP3} edge from parent[<-,black]}
child {node {arbitrary application} edge from parent[<-,black]}
edge from parent [<-,red]
}
;
\end{tikzpicture}
\caption{Reuse of TLS as the mechanism for secure communication.}
\label{fig:tls-reuse}
\end{figure}Including a personal macros file
\usepackage{hcg-personal}% hcg-personal.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hcg-personal}[2019/04/16 hcgatewood's personal style file]
% Be sure to use \RequirePackage instead of \usepackage
\RequirePackage{amssymb}
% ...\href{url}{text} link to url\url{url} link to url, without the
representative link text\hyperref[label_name]{''link text''} link to
label_name% Include a centered picture of a gull, with caption
\begin{figure}[ht]
\centering
\includegraphics[width=0.5\textwidth]{gull}
\caption{A picture of a gull.}
\label{fig:gull}
\end{figure}\begin{table}[ht]
\centering
\begin{tabular}{c|c|c|c}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{\underline{Operator co-located}} & \\
& Agent & Controller & Witness \\
\hline \hline
Manned & \cmark & \cmark & \cmark \\
\hline
Unmanned & & \cmark / \xmark & \cmark \\
\hline
Logical swarm & & \cmark / \xmark & \cmark \\
\hline
Swarm constituents & & & \\
\end{tabular}
\caption{Comparing manned, unmanned, and swarm systems.}
\label{tbl:manned-unmanned-comparison}
\end{table}% Example calendar-based Gantt chart
\ganttset{calendar week text={\currentweek}}
\begin{ganttchart}[
inline,
x unit=0.7mm,
time slot format=isodate,
]{2018-12-03}{2019-05-24}
\gantttitlecalendar{year, month, week} \\
\ganttbar{Synthesize}{2018-12-15}{2019-02-01}
\end{ganttchart}Forest, for better trees
Example
\begin{figure}[ht]
\centering
\begin{forest}
for tree = {minimum size=3em},
internal/.style = {draw,circle},
affected/.style = {internal,fill=lightgray},
changed/.style = {internal,dashed,edge={dashed},for children={edge={dashed}}},
leaf/.style = {draw,square,fill=black,text=white,font=\sffamily\bfseries},
[k,affected
[k14,affected
[k12,internal
[k1,internal [u1,leaf]]
[k2,internal [u2,leaf]]
]
[k34,affected
[k3,changed [u3,leaf]]
[k4,internal [u4,leaf]]
]
]
[k58,internal
[k56,internal
[k5,internal [u5,leaf]]
[k6,internal [u6,leaf]]
]
[k78,internal
[k7,internal [u7,leaf]]
[k8,internal [u8,leaf]]
]
]
]
\end{forest}
P(n, k) k-permutations from
n-sized setC(n, k) k-combinations from
n-sized setk+1 where k=2 evaluate for some assigned variablepandoc.csspandoc --standalone --self-contained --css=pandoc.css --katex=katex-0.10.0/ --from markdown+smart+emoji in.md -o out.html
convert in.md to standalone out.htmlpandoc --from markdown+smart --pdf-engine=xelatex -V urlcolor=blue in.md -o out.pdfpandoc --from markdown+smart --pdf-engine=xelatex --template eisvogel --listings in.md -o out.pdf
using a templatedd if=2018-04-18-raspbian-stretch.img of=/dev/sdX bs=4M conv=fsync status=progressunzip -p 2018-04-18-raspbian-stretch.zip | dd of=/dev/sdX bs=4M conv=fsync status=progresscat instead of ddsudo sync/boot/config.txt
and rebootgpio
command-line utility (requires root)
gpio readall view (somewhat idiosyncratic) pin number
mappingsgpio mode 1 pwm set pin 1 to use PWMgpio pwm 1 1023 set pin 1 to max PWM
valuegpio mode 16 out set pin 16 to output
modegpio write 16 1 set pin 16 to highCV means “constant voltage”,
CC means “constant current”/etc/dhcpcd.conf then
reboot<alt><space>vcgencmd
(video
core general commands): vcgencmd commandslsb_release -a/etc/hostnameapt list --installed list
installed packagesi386, amd64, armel,
and more
i386
vs. amd64: 32-bit vs. 64-bit of x86 architectureifup and ifdownhostname -I list “all” resolvable addresses for the
hostip -f inet addr show eth0 | grep -oP 'inet \K[\d.]+'
get the IPv4 address on interface eth0 (\K
means “output starting here”)Set
proxy location: something like the following in
/etc/environment (username:password only
as-necessary):
export http_proxy=http://username:password@proxyhost:port/
export https_proxy=https://username:password@proxyhost:port/
export ftp_proxy=http://username:password@proxyhost:port/Run
sudo commands through a proxy: add line
Defaults env_keep = "http_proxy ftp_proxy" using
visudo command
blockdev
blockdev --getbsz /dev/sda get block size of
sdablockdev --getsize64 /dev/sda get total size of
sdadd
fdisk
fdisk -l | grep "Sector size" disk sector sizestat
stat file information about filestat -f file information about filesystem on which
file residesatime: access, or last time file was readmtime: modify, or last time file content was
modifiedctime: change, or last time file metadata was
modifiedtouch to update timestampsatime
is generally not straightforward, often replaced
with relatime
sudo journalctl print all logssudo journalctl -f follow logs tailsudo journalctl -u jcaus print all logs for
jcaus unitsudo systemctl enable ~/some.service enable from unit
file at
arbitrary locationalias=jcaus.service in the
[Install] sectionCreate unit file
# /etc/systemd/system/big-old-test.service
[Unit]
Description=a big old test
[Service]
ExecStart=/bin/bash -c "while true; do date; sleep 1; done"
[Install]
WantedBy=multi-user.targetReload systemd:
sudo systemctl daemon-reload
Enable service:
sudo systemctl enable big-old-test
Optionally, start right away:
sudo systemctl start big-old-test
dmesg
read/write kernel messages, e.g. to check Ethernet cable connection and
statuslsblk
list block
devices (type of device file), where
e.g. mmc refers to a MultiMediaCardlscpu
display information about the CPU architecturelsusb
list USB devicesmmv move
and rename files in bulkpasswd
change passwordping
send ICMP ECHO_REQUEST to network hosts (ping6) (ping
vs. ping6)pwgen
generate passwordsssh
secure login and shellstrace
trace system calls and signals (cheat
sheet)sysctl
view and configure kernel parameters at runtimetar save
many files as a single filetime time
a simple commanduname
print system information like OS, kernel name, machine hardware
namevimdiff
view useful diffs between two files (cheat
sheet)#!/usr/bin/env bash most
portable hashbangcommand gist twilio.js call
non-aliased version of gistcp foo{,bar} expands to cp foo foobardate +%s number of seconds since
the Epochdate --set='Fri Nov 22 23:36:40 UTC 2019' set system
timedate -u date and time in UTCdhclient eth0 configure interface eth0
with dynamically-assigned
IPdmesg -w like tail -f for
dmesgdu -s . | awk '{print $1}' get
recursive size of current directory in bytesecho -e 'hello\nworld' print
literal newline (can also use printf)echo foobar | gzip | zcat pipe
directly to gzipenv print environment variablesfind . -exec touch {} \; recursively change date on all
files in directoryfind . -type f -name '*.go' -print0 | xargs -0 sed -i '' 's/MapMany/Map/g'
recursively replace in all filesgrep -RI foobar . recursively search all text-like
files for foobargsed 's/\x1b\[[0-9;]*m//g' < terraform_apply.txt > terraform_apply.log
remove
ANSI color codes from texthg status | sed -n 2p | awk '{print $2}' get
line 2, column 2 of hg status outputip -f inet addr show eth0 | grep -oP 'inet \K[\d.]+'man 2 unshare view
the man page for unshare from section
2mdfind -name .txt -onlyin ~/magma/ macOS version of
find using Spotlight indexnetstat -tulnp list ports and determine what process is
bound to a portnmap -p - localhost localhost port scannohup livedown start notebooks_misc.md --port 8080 &
start background command to last past terminal
sessionopenssl rand -hex 20 generate random passwordpbpaste | jq pretty-print copied JSON (replace
pbpaste with appropriate
clipboard manager)ps -o ppid= 50377 get
parent PID of PID 50377ps aux | grep -i net case-insensitive search for
processes matching netrename 's/foo/bar/' \* rename files by replacing
all occurences of foo with barroute -n show
routing information like gateway and genmasksleep 4 sleep for 4
seconds, or use m, h, d for
minutes, hours, dayssort favorite_words.txt | uniq -d print non-unique
linessudo -E python3 preserve environment variables when
sudo-ingsudo hwclock --set --date 'Fri Nov 22 23:36:40 UTC 2019' && sudo hwclock --hctosys
update
hardware clocksudo ncdu -x -o out.ncdu / && ncdu -f out.ncdu
device disk utilization TUItail -f out.log | ag 'foo|bar' --passthru highlight
streamed log file for foo and bar
(case-insensitive)tail -f out.log | egrep 'foo|$' -i --color highlight
streamed log file for foo with
grep (case-insensitive)tar czf target.tar.gz file1 file2 file3 create gzipped
tar filetar xzf source.tar.gz extract gzipped tar filetextutil -convert txt main_tf_08_06_2020.rtf convert
to/from plaintextunset COMPOSE_FILE unset
environment variableswatch ip addr watch and wait for IP
changesxxd -p < /dev/input/event1 convert binary data from
event1 to printable formatstdout
setvbufstdout to be line-buffered:
setlinebuf(stdout);stdbuf -o L grep jcaus /var/log/syslogcomplete | grep systemctlcomplete -F _systemctl sc/proc holds
process-specific information, /sys
exports kernel objectsgzip
vs. zip: tar is archiver,
gzip is
compressor; zip does both in
one step^(Date|added|deleted|modified|renamed): search term to
jump between changed files_GIT_BRANCH=master git-quick-stats --git-stats-by-branch--soft)--hard)git diff remotes/origin/master --name-only only
names of changed filesgit commit --amend rebase/replace
most recent commit (and message)git rebase -i HEAD~3 interactive rebase of most recent
3 commits (HEAD~3 actually points to the parent of the last
commit to update)git push origin my-branch -f force push to
my-branchgit branch -a list all branches (local and remote)git branch -d local-branch delete
local-branchgit checkout --track remotes/origin/remote-branch
checkout and track remote-branchgit merge other-branch merge other-branch
into current branchgit checkout -b new-branch a9c146a create
new-branch from commitgit log --oneline -S hosting-helm-private commits which
changed the occurrences of the stringpull_request,
pull_request_target, etc.$('#header') return first element with ID
header$$('img') return all img elements$$('.check').forEach((e) => e.click()) click all
elements with class checknpm install -g git+https://github.com/hcgatewood/livedown
install (global) package directly from GitHubURI := scheme:[//authority]path[?query][#fragment]authority := [userinfo@]host[:port]
pageshow and pagehide window
events// Reload the window when page loaded from page cache
pageshow = function (event) {
socket.emit('ready')
if (event.persisted)
window.location.reload()
}
// Hide the body when leaving page to prevent
// "blinking" on navigation back/forward to page
pagehide = function (event) {
// The '$' operator can be from e.g. zepto.js
$('body').css('opacity', '0')
}
// Install listeners
// - pageshow: any time the page is loaded, whether from
// page cache or otherwise
// - beforeunload: any time the page is destructed, whether
// from forward/back or closing
window.addEventListener('pageshow', pageshow)
// window.addEventListener('pagehide', pagehide)
window.addEventListener('beforeunload', pagehide)mov (%ebx), %eax /* load 4 bytes from memory address in ebx into eax */
mov %ebx, var(,1) /* move contents of ebx into the 4 bytes at memory address var */
mov -4(%esi), %eax /* move 4 bytes at memory address esi+(-4) into eax */
mov %cl, (%esi,%eax,1) /* move contents of cl into the byte at address esi+eax */
mov (%esi,%ebx,4), %edx /* move the 4 bytes of data at address esi+4*ebx into edx */Trap vs. interrupt: trap is an interrupt generated in a user process (software-generated exception); an interrupt in general can be asynchronously generated by hardware
PHY: circuitry connecting the link layer device (e.g. a wider Ethernet NIC) to the physical medium
CMOS, aka nonvolatile BIOS memory: stores e.g. system time, BIOS settings
Recursive page tables (in xv6) (general description)
Virtual to physical address translation:
Translation registers:
Interrupt description table:
Stack during subroutine call:
Inode (disk inode in xv6):
Network server environments in JOS (we implemented green boxes):
Processor vs. CPU:
ID rather than
Id^// Code generated .* DO NOT EDIT\.$stress
runs a test until it fails (install with
go get golang.org/x/tools/cmd/stress)&Obj{} over new(Obj) where possible,
as the struct literal is newer and idiomatic for applicable
use-cases// Deprecated: use alternative... mark object as
deprecated`) encase non-escaped string
literalsio.Reader, io.Writerenc := json.NewEncoder(<file>) create
encodererr := enc.Encode(&v) encode v to filego test, by
defaultgo test -count=1 ./services/state/... force no-cache
test runimport assert "github.com/stretchr/testify/require"
have failed assertions end the test immediatelygo test -c ./services/lte/obsidian/handlers/ && while ./handlers.test -test.run=TestAPNResource -test.count=100 -test.failfast ; do date ; done
run
flaky test till failure.Alexa app > Settings > Music & Podcasts > Spotify,
disable and re-enable Spotify skill~/Library/Application Support/Spotify/Users/hcgatewood-user/local-files.bnksystem preferences > displays > arrangementsudo mdutil -a -i off disable Spotlight indexing~/Library/Application Support user-specific application
storageshift-alt-click Bluetooth icon > Debug > Reset Bluetooth modulemarkdown-toc --maxdepth 2 notebooks_misc.md | pbcopy
generate the table of contents for this file using markdown-tocpbpaste | say -o out.aiff convert to speech stored as
AIFF
format
pbpaste
pastes from the system clipboard-r 250 set output to speak 250 words per minute-f in.txt rather than taking from the clipboard, pull
from in.txtout.aiff using e.g. VLC
Using launchctl (overview) (docs)
Example launchctl plist file
<!-- ~/Library/LaunchAgents/com.user.login.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.login</string>
<key>ProgramArguments</key>
<array><string>/Users/Hunter/.login.sh</string></array>
<!-- <key>StandardOutPath</key> -->
<!-- <string>/Users/Hunter/.login.out</string> -->
<!-- <key>StandardErrorPath</key> -->
<!-- <string>/Users/Hunter/.login.out</string> -->
<key>RunAtLoad</key>
<true/>
</dict>
</plist>Example login script
# ~/.login.sh
PATH=/usr/local/bin:/usr/bin:/bin
livedown start '/Users/Hunter/Dropbox (Personal)/notes/notebooks_misc.md' --port 8081cmd-ctrl-q lock macctrl-down app exposectrl-up mission controlfn-up page upfn-down page downcmd-b open Spotlight contents as a search engine
querycmd-ctrl-space emoji searchcmd-shift-. show hidden files in Findercmd-shift-g go to folder, with tab completealt-click move
cursor location to mouse pointercmd-2click open URLcmd-shift-2click select URL or file pathcmd-shift-3 screenshot whole desktopcmd-shift-4 screenshot specified region
space specific windowspace hold to move chosen areacmd-shift-5 screenshot
options and recordingscmd-shift-t undo closing tab, back one frame. forward one frame/usr/local/bin/BluetoothConnector 00-00-00-00-00-00 --notify,
substituting desired device’s MAC address? help, with option to show all/advanced commandsyy yank current URLP paste clipboard in omnibox of new tabgu go up URL hierarchygU go to root of URL hierarchygi focus first text input on the pageyf copy link URLyt duplicate current tabW move current tab to new window>>, << move tab to the
right/left]], [[ go to next/previous page (e.g. for
Google search results)c to enter caret mode (optional)v to enter visual modey, Y to yank selected textmap H previousTab map L nextTab map J goForward map K goBack map ' Marks.activateGotoMode map \ passNextKey normalmas, a CLI for
the Mac App Storebrew update-reset hard update to fix any potential
merge issuesbrew cleanup remove all old formulasbrew update && brew upgrade update Homebrew,
then upgrade all outdated packagesbrew deps --installed list top-level formulas (seems to
not be working…)z will sometimes stop working and cause
abort trap: 6, fix with
brew reinstall gawkpyenv version currently set Python versionpyenv versions all installed, pyenv-selectable
versionspyenv install --list list Python versions available for
installationpyenv install 3.4.10 install version as a
pyenv-selectable versionpyenv local show version local to current working
directorypyenv local 3.4.10 set local version for current
working directorypyenv local --unset unset local versionpyenv global 3.7.4 set global (per-user) versionsudo apt-get install python-pip python-dev build-essentialsudo apt-get install python3-pippython3 -m pip install ipythonpython3 -m pip install some-packagepython def some_function(): """A default one-line docstring.""" passm, e = math.frexp(4.2); m * 2**e == 4.2 exactly
(extract float’s mantissa and
exponent)a, b = (4.2).as_integer_ratio; 4.2 == a / b
exactly'{:5.5}'.format('xylophone') truncates and pads to
exactly xylopopen
modes
r readw write (truncate first)a appendr+ read/writeb binary (don’t decode file’s bytes contents to
str)await asyncio.gather(f(), g(), h()) run function calls
concurrentlyasync for elt in awaitable_iterable iterate over async
iterableSimpleNamespace
for the most simple needsnamedtuple
under limited circumstancesPrefer base classes where applicable
Iterable for generic iterables (anything usable in
for)Sequence where a sequence (supporting len
and __getitem__) is requiredExample ```python from typing import Callable, Union, Optional, List
def f(num1: int, my_float: float = 3.5) -> float: return num1 + my_float
x: Callable[[int, float], float] = f
# Optional variables are allowed to be None def send_email( address: Union[str, List[str]], sender: str, cc: Optional[List[str]], bcc: Optional[List[str]], subject=’’, body: Optional[List[str]] = None ) -> bool: ```
__all__ = [] construct determines what happens on
import * from.pyc files (structure)
(create)dis.dis(func)a abbreviated weekdayW week number of the year-m month as decimal number-d day of the month as decimal numberX time, with secondsimport pdb; pdb.set_trace() enter PDB
programmaticallypp obj.__dict__ pretty-print an object as a dictunittest,
the standard library’s testing framework
unittest.TestCasetestsetUp, tearDown, setUpClass,
tearDownClass to handle before/after every and before/after
alldebug instead of run to allow debugger
usage and original exception propagationunittest.mock,
the standard library’s mocking
library
Mock records calls and can be stubbedMagicMock also autogenerates magic methods like
__str__AsyncMock returns awaitablesPoint = collections.namedtuple('Point', ['x', 'y']); p = Point(11, y=22)
create a named
tupleassert a == b, 'Something went wrong' prescribe an
assertion-failure messageexcept (IndexError, ValueError) as err catch
multiple possible errorsformat(0xdeadbeef, '032b') format
to binary number with leading zerosfrom pprint import pprint import default
pretty printerprint(sys.argv[1:]) command-line
argumentspython3 -m http.server start
simple HTTP serverimport asyncio
async def main():
"""Asynchronous main function."""
print('hello')
await asyncio.sleep(1)
print('world')
if __name__ == '__main__':
asyncio.run(main())def overrides(interface_class):
"""
Allow runtime checking of @override() decorator.
Usage:
> @overrides(logging.Handler)
> def emit(self, record):
> pass
See https://stackoverflow.com/questions/1167617/#answer-8313042.
"""
override_err = 'Overriden method does not exist in parent.'
def overrider(method):
assert method.__name__ in dir(interface_class), override_err
return method
return overridervagrant scp magma:/var/opt/magma/certs/gateway.key ~/Desktop/magma_protos/gateway.key ; vagrant scp magma:/var/opt/magma/certs/gateway.crt ~/Desktop/magma_protos/gateway.crtvagrant ssh magma -c 'cd magma/lte/gateway && make test'
run command over SSHvagrant box list list current imagesvagrant box add magma_dev_tmp magma_dev_virtualbox.box
add image from Packer outputvagrant cloud auth login login using info from
$ATLAS_TOKENvagrant cloud auth whoami who I’m logged in asvagrant cloud publish fbcmagma/magma_dev 1.0.1586316960 virtualbox magma_dev_virtualbox.box
publish new versionWaiting for SSH to become available... can take 5-10
minutespacker build magma-dev-virtualbox.json build image from
config
COPY over ADDADD and COPY only commands to dynamically
invalidateARG change invalidates line of first useRUN only invalidates if command to run changesdocker exec orc8r_controller_1 tcpdump -U -w - 2>/dev/null -- > controller.pcap
tcpdump to file on host machinesh docker build -t tcpdump - <<EOF FROM ubuntu RUN apt-get update && apt-get install -y tcpdump CMD tcpdump -i eth0 EOFdocker run -i --net=container:orc8r_controller_1 tcpdump tcpdump -U -w - 2>/dev/null -- > controller_and_proxy.pcap
capture directly onto hostdocker cp ~/Downloads/out.sql orc8r_postgres_1:/ copy
file to Docker containerdocker exec -it orc8r_maria_1 mysql -u magma_dev -p
exec command with args in container (e.g. bash)docker ps list containersdocker system df what’s available to prunedocker system prune docker doesn’t perform garbage
collectiondocker-compose logs -f controller* follow logs for
controller containerdocker-compose ps list containers (in context of
docker-compose.yml)docker-compose ps --services list services.help show help.tables list tables.schema ZRECIPE show a table’s schema.backup backup.sqlite create a consistent backup of the
DBredis-cli -p 6380 connect to Redis locally on port
6380keys * find all keysget mobilityd:systemd_status get value of key
mobilityd:systemd_statusmysql -u magma_dev -p access as user
magma_dev, with password promptshow databases;use magma_dev; use magma_dev databaseshow tables;describe some_table; show schema for tabletable some_table; print full tableselect * from some_table limit 10;select count(*) from some_table; number of rows in
some_tableselect count(distinct key) from certificate_info_db;
number of distict values in column keyselect id,convert(data using utf8) from reservations;
convert
a blob field data into readable UTF-8select id,convert(data using utf8) from reservations where data like '%testHardwareAssetIds%' limit 1;
search e.g. a JSON field for particular keydelete from certificate_info; delete all rowsdelete from states where type='directory_record' and key='id=foo';
delete based on column contentsdrop table some_table;begin transaction isolation level serializable; begin
serializable transactioncommit; commit transactionend; rollback transactionSKIP LOCKED (more)
SERIALIZABLE
isolation levelpostgresql-client version to match serverpg_dump -U magma -h orc8r.remote.host magma > /tmp/pgdump-prod-$(date +%s).sql
dump remote magma database contentscreatedb -U magma_dev -T template0 pgdump-prod-1598488376
create
new virgin databasepsql -U magma_dev pgdump-prod-1598488376 < /var/lib/postgresql/data/pgdump-prod-1598488376.sql
import dumped database into created databasedropdb -U magma_dev pgdump-prod-1598488376 drop
databasepsql -U magma_dev access as user
magma_dev, with password prompt\l list all databases\c magma_dev use magma_dev database\dt list all tables in current database
(\dt+ for more info)\d+ hwid_to_hostname detailed information on table
hwid_to_hostnameexplain select task_id from test_task_bag limit 1 for update skip locked;
explain
query planselect key, encode(value, 'escape') as value from directoryd_blobstore where type='hwid_to_hostname';
decode
bytes to string using encode
string functionselect * from cfg_entities \g out.table output
query to file\copy (select * from cfg_entities) to out.csv csv header
output query to CSV fileconstexpr
indicate a variable or function value can be evaluated at compilation
time++ -- () [] . ->static
keyword inside a function: visible in function’s scope, but extends
lifetime across all calls to function (and stored in the usual
data or bss sections)main
function signature:
int main (int argc, char *argv[], char *envp[])
argc number of command-line argsargv null-terminated array of C strings representing
the passed command-line args
envp null-terminated array of environment variable
strings
"variable=value"envpgetenvperror(char *msg): print msg and error
message corresponding to errnoexit(EXIT_FAILURE) portable exit with failure status
static inline
modifiertypedef:
typedef struct { int x, y; } Point;int arr[arr_size]; sizeof(arr);struct vertex_t vertex = {0};memset(&vertex, 0, sizeof(vertex_t));isatty: test
whether file descriptor refers to a terminalwait(), double fork(),
or ignore in parent with signal(SIGCHLD, SIG_IGN)
#include directive works: quotes first search
current working directory, otherwise "" and
<> are largely similarecho | gcc -xc -E -v - print
the include paths used by
gcc/g++gcc --print-file-name=libc.a look
for a library, e.g. libc.so or libc.aPragmas: provide additional information to the particular compiler, beyond language-standardized directives
#pragma once
modern alternative for providing #include guards (stackoverflow)Current
function name: __func__
Variadic macros: macros with a variable number of arguments
Trigraphs:
nine triplets, each beginning with ??, which can optionally
be replaced by their alternative single-character representations;
e.g. ??!??! represents ||, the logical or
operator
Stringification
with #
// Will actually print EXP
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
WARN_IF(x == 0); // prints "Warning: x == 0"Token
concatenation with ##
#define macro_start i ## n ## t m ## ain(void)
macro_start; // -> int main(void);Token
expansion: in function-like macros, if either of the tokens next to
a ## is a parameter name, it is replaced by its actual
argument before ## executes
#ifdef DEBUG
#define DEBUG_PRINT(...) fprintf( stderr, __VA_ARGS__ )
#else
#define DEBUG_PRINT(...) do { } while (0)
#endif // DEBUG$* the stem which an implicit rule matches.PHONY
targets if a file with the target’s name exists, prefer the target
over the file
make -j make non-dependent executables/libraries in
parallelmake --debug=v print debug info$(PROTO_LIST): %_protos: build_list static
pattern rulemake help: ## Print help text @grep -Eh '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'make printvars: @$(foreach V,$(sort $(.VARIABLES)), \ $(if $(filter-out environment% default automatic, \ $(origin $V)),$(warning $V=$($V) ($(value $V)))))CMakeLists.txt:
set(CMAKE_BUILD_TYPE Debug)cmake -DCMAKE_BUILD_TYPE=Debug <...>set(CMAKE_EXPORT_COMPILE_COMMANDS ON)compile_commands.json file by
either moving the file into some directory above the working directory
(as in the link above), or utilizing a .ycm_extra_conf.py
to point
to the fileinclude-what-you-use,
which can be integrated
with CMake
recv is mysteriously reading zero bytes, despite
peer not closing connection, make sure the provided buffer length is
non-zeronmap -p - localhostkill -9 <pid>rr: related
debugger with deterministic replay and reverse execution.gdbinit upgrade (doesn’t play well with gdb’s
TUI)gdb --args ./executable arg1 arg2 arg3(gdb) r arg1 arg2 arg3Automatically
run executable:
gdb -ex run --args ./executable arg1 arg2 arg3
Segmentation fault (core dumped)gdb path/to/binary path/to/coreulimit -c unlimited.gdbinit
init script: run commands on gdb startup
.gdbinit from
local dirInterrupt execution programmatically
#include <signal.h>
raise(SIGINT);Save
command history across sessions:
echo 'set history save on' >> ~/.gdbinit && chmod 600 ~/.gdbinit
<C-c> interrupt executionc continue executionsi step a machine instruction (s for
source instruction)ni same as si but step over function calls
(n for source instructions)finish run until current function finishesreturn discard current stack frame and return
immediatelybreak 120 if x == 3
120 can be <line>,
<file>:<line>,
<function>if x == 3 can be any conditional, or omittedinfo break info on all breakpointsdisable 3 disable breakpoint 3enable 3 enable breakpoint 3del 3 delete breakpoint 3advance 120 run until reach line 120 (or
some location)wh open TUIbt stack backtracelist surrounding source linesframe current line, function, and args; change stack
frameup/down move up/down stack frameinfo
i r current registersi address <symbol> address of
<symbol>i variables variables known in current scopei locals local variablesi args args to current stack framei thread running threadsx
examine memory
x print raw contents of memory
x/nfu addr
n repeat countf display
format: hex, decimal,
unsigned decimal, octal, two
(binary), address, char, float,
string, zero-padded hex, rawu unit size: byte, halfword
(2 bytes), word (4 bytes), giant word (8
bytes)x/s <addr> print full null-terminated string
starting at <addr>x/5i $eip print next 5 instructions w/ next instruction
at topp(rint) print evaluated c expression
p/x $cs print content of $cs registerwh open TUIlayout <name> change layout, where
<name> can take a superset of:
src source, commandsplit source, assembly, commandasm assembly, commandregs add registers to current layoutfocus <name> set main focus to
<name> sub-window, similar to layout
abovewh <name> <count> change window height of
<name> by <count>, where count can
be positive or negativetui disable or <C-x> a disable the
TUIinfo frame print human-readable information about the
active stackp ($ebp-$esp)/4 + 2 print the “length” of the stack
necessary to see the stack down to the saved ebp and ret
addrx/16xw $esp print the full stack, where 16 is the
output from the above commandx/2xw $ebp print saved ebp and saved ret
addrinfo line info about the current line of the active
framedisas print dissembled x86 instructions starting at
eipdisas /r $eip,+24 print 24 instructions, including each
instructions specific bytesdisas /s $eip,+24 print 24 instructions, including
relevant source codedisplay/<format> <expr> to display
<expr> after every command to gdbbreak <linenum> break just before
<linenum> executes in the current filebreak <filename>:<linenum> break just
before <linenum> executes in
<filename>until <linenum> step until source’s
<linenum> is reached, or would exit current
stackwatch <expr> to break when the evaluated value of
<expr> changes
set can-use-hw-watchpoints 0 may have to enable software-only
watchpoints (to function properly on a VMWare VM?)delete display clear all auto-displaysprint or set to set
values/edit memory during debuggingset reqpath = "foo" where reqpath is a
char*, sets the reqpath string to
"foo"set {int}0xbffff59c = 0x10 set the memory at address
0bxffff59c to the value 0x10set $esp += 4 increment $esp register by 4define <command> define a
user alias to <command>target record-full record all actions so can reverse
debugset follow-fork-mode childbr * <addr> break at addr'deadbeef'H.pem Privacy
Enhanced Mail, a Base64-encoded bucket,
where file contents are indicated in the header/footer lines.key any type of key, usually a private key.csr certificate signing request.pfx PKCS #12, a generic
archive format; often: encrypted and signed bucket containing a private
key and associated X.509 certificate/chain.pem,
.cer, .crt, .der,
.pfxopenssl pkcs12 -in admin_operator.pfx -nocerts -nodes -out out.key
extract private key from PKCS #12 (or
-nokeys to extract just certificates) (man)
(dealing
with bag attributes)openssl rsa -text -noout -in out.key examine RSA key (man)
(more)openssl x509 -text -noout -in certifier.pem examine X.509 certificate (man)openssl req -noout -text -in controller.csr examine PKCS
#10 certificate signing request (man)openssl verify -CAfile ca.pem -untrusted intermediate.cert.pem cert.pem
verify
certificate chainopenssl asn1parse -i -in out.crt examine ASN.1-parsed
fieldsopenssl s_client -CAfile /var/opt/magma/certs/rootCA.pem -connect bootstrapper-controller.magma.test:9444
debug
SSL handshake (man)
h^1000(password), and user successively authenticates by
sending h^999(password), h^998(password),
…S given
(g, p, g^S mod p) (generator, prime, key fragment) being a
hard problem
10.0.0.0 - 10.255.255.255.255172.16.0.0 - 172.31.255.255192.168.0.0 - 192.168.255.255(source address, source port, destination address, destination port)
127.0.0.1
vs. 0.0.0.0: local-only vs. “every available network
interface”
tcpdump -D list available network interfacestcpdump -i lo udp port 49183 -vv -X sniff
UDP packets on local/loopback 49183 porttcpdump -i any port 8080 sniff traffic to port 8080 on
any interfacetcpdump -i lo port 2461 -w dump.pcap sniff packets sent
to port 2461 from and to the local device; and write to
dump.pcapmergecap *.pcap -w merged.pcap merge pcapsnc -l 8080 listen on port 8080nc -l 8080 < out.html serve out.html
over port 8080nc localhost 8080 connect to
127.0.0.1:8080 over TCPnc -u localhost 8080 connect to
127.0.0.1:8080 over UDPnc localhost 8080 > out.html receive to
out.html from 127.0.0.1:8080ip addr find broadcast address for desired network
interface (can also use ifconfig)socat -u udp-recv:8080 - start receiversocat - udp-sendto:127.255.255.255:8080,broadcast start
senderglibc
under the header <rpc/rpc.h>
Source code and documentation in glibc/sunrpc
with:
git clone git://sourceware.org/git/glibc.git
git checkout --track -b local_glibc-2.27 origin/release/2.27/masterxdrlib
for high-level packing/unpacking (example)rpcbind must be running on the server’s machine.
rpcbind records and resolves mappings from RPC program
numbers to universal addresses.
{RPC program number, version of that RPC program, requested transport protocol} -> {TCP/UDP port}{IP address, port number} pairrpcbind were called
portmaprpcinfo report RPC info such as mapped programs and
transport types
rpcinfo -p relevant portsrpcinfo -s concise reportrpcgen -C -N -a add.x generate stubs from
add.x specification
-C ANSI C stubs-N C-style declarations (allows e.g. multiple arguments
passed per stub)-a create example usage filesnmap -p - localhost scan listening ports (e.g. to
ensure rpcbind is running)netstat -tulnp list listening socketsnc -u localhost 49183 send UDP packets to localhost
port 49183tcpdump -i lo udp port 49183 -vv -X sniff
UDP packets on local/loopback 49183 port (use
rpcinfo -p to determine port)
-w dump.pcap to dump to file readable by Wireshark, which can
understand the RPC protocol (may have to set a Wireshark option or
two)xdr_bytes()add
and attach commands
attach attaches the specified lockeradd does the same but also edits $PATH and
$MANPATHUseful to e.g. access academic papers released only to people on
MIT’s network. - Why MIT’s
VPN is great - Install the VPN
software: Cisco’s AnyConnect VPN - Log
in to the VPN with Duo: VPN address is
vpn.mit.edu/duo
We want to be able to log in easily–that is, without providing a
password. We’ll use the Kerberos
protocol. - Install
Kerberos Extras to allow creation of a Kerberos ticket - Acquire a
Kerberos ticket using
the Ticket Viewer app. Alternatively, use
the kinit family of programs: -
kinit <athena-username> get Kerberos ticket -
klist list tickets - kdestroy destroy tickets
- Add the following block to your ~/.ssh/config file. This
will allow login with ssh athena, and will automatically
use local Kerberos tickets.
```sshconfig
Host athena
HostName athena.dialup.mit.edu
User <athena-username>
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes
StrictHostKeyChecking no # optional, fixes an issue I kept running into
```
/etc/krb5.conf, though on Macs it may be at
/Library/Preferences/edu.mit.KerberosWe want to be able to edit files in our Athena workspace using the
tools on our local machine. - Common file-sync/remote editing tools: SSH, SCP, rsync - File transfer overview
and tools - SSHFS,
generic file-transfer solution for editing files on an Athena directory
from your local machine - OpenAFS is an AFS-specific
alternative to SSHFS, and one officially supported by MIT - Intro
- How
to install OpenAFS on Mac - Install AuriStor’s
implementation of AFS, as is recommended by IS&T (MIT’s
cell is athena.mit.edu)
- Optionally allow
usage from menu bar - Log into AFS: kinit <username> && aklog
- Commands that touch many files are slow over mounted remote
filesystems, so if your editing environment makes calls like
git status this will slow down the editing environment and
make it appear sluggish. Instead, we could use rsync to
copy files over automatically. Sample rsync script: -
824-sync pull copy remote files to local machine one time -
824-sync push copy local files to remote machine on changes
- Make sure you performed the Better remote login steps
above–this won’t work without a Kerberos ticket, etc. - May need to
install fswatch,
e.g. brew install fswatch
```sh
# Store this in a script such as `~/.scripts/824-sync`
# Usage: 824-sync <push/pull> [-f]
# This script syncs the `src` directory of my 6.824 work from the local machine
# to the Athena machine.
# This won't delete files on the Athena machine.
# It also won't overwrite "newer" on the receiver unless you pass `-f`.
shared_dir="src" # shared dir across local, remote
src_dir="/Users/Hunter/Desktop/mounts/${shared_dir}"
dest_dir="/mit/hcg/6.824/${shared_dir}"
exclude="*.swp"
# Return early if no $1
[ -z "$1" ] && echo "Usage: <push/pull> [-f]" && exit 1
# Don't protect newer files on receiver when -f passed
[[ "$2" = '-f' ]] && u='' || u='u'
rsync_push="rsync -az${u}P --exclude=${exclude} ${src_dir}/ athena:${dest_dir}"
rsync_pull="rsync -az${u}P --exclude=${exclude} athena:${dest_dir}/ ${src_dir}"
# Just pull and exit
if [ "$1" = 'pull' ] ; then
echo 'pulling...'
$rsync_pull
exit
fi
# Continuously push
echo 'pushing...'
$rsync_push
echo 'watching...'
fswatch -or "$src_dir" | while read ; do $rsync_push ; done
```
todo_yyyy-mm-dd_hh-mm-ss_epoch.txtconfig.txt; requires driver for
touchscreen capabilitiesevdev module to parse controller input eventsscreen /dev/ttyUSB0 115200 -S session-name start new
session-name at 115200 baud on ttyUSB0screen -ls list sessionsscreen -x attach to some session<C-a>d detach from sessionscreen -r session-name reattach to
session-namescreen -X -S session-name quit kill detached
session-name<C-a>\\ kill attached sessiontmux ls list sessionstmux a attach to some sessiontmux a -t session attach to sessiontmux kill-session -t session kill
session:set -g mouse on enable mouse, enable scrollback:set-window-option mode-keys vi, then
prefix-[ enable vim-like page scrollingprefix-% new pane, vertical splitprefix-" new pane, horizontal splitprefix-o next paneprefix-<space> cycle pane layoutsprefix-q show pane numbersprefix-} swap panesprefix-[ enable page scrollingprefix-x kill paneprefix-c create new windowprefix-d detach:h usr_27.txt)
s/pattern/string/cgiI
I don’t ignore case for the patternfoo \zsbar\ze baz partial
match (lookbehind/lookahead)hi SignColumn ctermbg=none set
background color to transparent for the sign column:syntax list syntax items for current buffer:syntax match mkdBlockquote "\[.\]" add
new syntax itemd) delete to end of the sentencedas delete a sentencecis change inner sentence]m, [m go to start of a method (e.g. a
def in Python)gv reselect previous visual selectionW, E, B operate on WORDs,
i.e. only whitespace breaks words:lne go to next item in quickfix listmM global, persistent mark
M% can switch between logically grouped C preprocessor
macros
matchit.vim
extensionruntime macros/matchit.vim in
vimrcc-y, c-e scroll screen up, down one
line:cq quit
with non-zero exit code:%s/\[x\]//gn print
number of matches of [x]store\|network1 search
store or network1:v/INACTIVE\|ACTIVE/p show
all lines not matchingc-w x swap splits:f current filename:tabm # move current tab to # location, or relative
(-1, +1, etc)tabdo, bufdo, windowdo : do
some command per unit
tabdo set nolist disable showing listchars in all
tabs:echo expand('%:p') print
full path of current file:pwd, :cd .. change
working directory3gt jump to tab 3@a) or file
(>out.log)
vimscript :redir @a :g/./p :redir END ```[b and ]b to quickly switch buffers
(requires unimpaired.vim):Buffers to fzf-jump to buffers (requires fzf.vim):e edit new file:new create
new unnamed buffer (also :enew,
:tabnew):bd delete current bufferCannot write, 'buftype' option is set error via
set bt=za toggle current fold (zc,
zo to close, open)zA toggle all folds related to cursor position
(zC, zO to close, open)zR open all foldszf create fold (in manual mode):'<,'>!tac reverse order
of selected lines (may have to use gtac):r insert contents of (named) file below cursorsort u on selection sorts the selection while removing
duplicatessort /./ sort,
but skip first character on each line:%!sort -k3nr sort
buffer by 3rd column, as numbers, reversedvim rsync://athena/6.824/src/ see directory in athena,
then can directly edit a file<c-r>a paste
register contents from register aqaq:g/Wrap/y A yank all lines containing
Wrap to register a:%S/old/new/g search/replace with case preservation
(requires vim-abolish):%s/^\W*\zs\w/\U&/g capitalize first letter of
every line:%s/\(\(^\(\s*-\s\)\?\)\|\(\w[.?!] \)\)\zs\w/\U&/g
janky attempt to capitalize the first word of every sentence:%s/Error\(f\)\@=/Fatal/g change all
Errorf to Fatalf via positive
lookahead regex<c-v><tab> add
literal tab character from insert modeg/SKIP because it is allocated with 0 resources/d delete
all lines matching the regexv/FREEZE CANDIDATE because it passed initial checks/d
delete
all lines not matching the regex:set spell enable:set nospell disable]s next error, relative to cursor[s previous error, relative to cursorz= find suggestions for word under cursorzg add word under cursor to “good words”zug remove word under cursor from “good words”:map debug
key mappingsvim -u NONE start
Vim without a .vimrc; if this fixes the slowdown, the
issue is in the .vimrc:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
:profile pause
:noautocmd qall!" Check installed packages (assuming using Vundle)
:PluginList
" Check imported scripts
:scriptnames]b next buffer]q next error]c next error]e exchange line below[e exchange line above]s next spelling error:BLines lines in current buffer:Commands colon commands:GFiles fzf based on .gitignore:History/ search history:History: command history:Buffers buffers:Lines lines in loaded buffers:Maps see all mappings:Marks saved marks:Tags tags in the projectg>, g< swap arguments right or
leftgs interactive mode for argument swap
s, S sort, unsortr reverseu, <c-r> undo, redog, G group, ungroup3 go to 3rd argumentae, ie environment
\begin{...} to \end{...}aQ, iQ double-quoted texta$, i$ inline math surrounded by dollar
signs:UltiSnipsEdit edit snippets for current
filetype
:h UltiSnips-interpolation help with interpolation
options
snippets/*Ultisnips/* 🌟Selected UltiSnips options
b beginning of line: expand only if the trigger is the
first non-whitespace word on the linei in-word expansion: snippet can be triggered in the
middle of a wordr regular expression: trigger is expected to be a
Python regular expressiont keep tabs: do not expand tabsA automatic: snippet will be triggered
automaticallyExample UltiSnips snippet definition
# ~/.vim/UltiSnips/tex.snippets
# Automatically expand when `\beg` is typed
snippet \beg "begin{} / end{}" bA
\begin{$1}
$0
\end{$1}
endsnippetgcc-7 -fdump-rtl-expand <*.c>perl <path/to/egypt> <rtl-file> | dot -Tpng -o out.png && open out.pnggcc-7 flag
-fdump-rtl-expandegyptdotSee this Stack Overflow answer for a list of alternatives to this approach.
brew install gcc
gcc-7 -fdump-rtl-expand <*.c>As a precursor, egypt wants to use output from GCC, while, apparently, Macs install clang and call
it gcc. To fix this, brew install gcc and use
gcc-7 instead of gcc.
RTL
representation, the Register Transfer Language, is a low-level
intermediate representation used during the last part of compiler work.
Egypt uses this representation
to create a graph-based call graph. The -fdump-rtl-expand
flag dumps the RTL representation for Egypt to use.
brew install graphviz
# Download egypt from http://www.gson.org/egypt/
cd <download-location>
perl Makefile.PL
make && make installperl <path/to/egypt> <generated-rtl-file> | dot -Tpng -o out.png
open out.pngDot
is a
directed graph visualizer. It takes the graph-specification output
from egypt and here outputs a PNG.